var layUI = null;
layui.use(['layer', 'form', 'element', "table", "dialog", "code"], function () {
    layUI = layui;
    var table = layui.table;
    var dialog = layui.dialog;
    var form = layui.form;
    var layer = layui.layer;
    var element = layui.element;

    //获取当前iframe的name值
    var iframeObj = $(window.frameElement).attr('name');

    //监听提交
    form.on('submit(search)', function (data) {
        console.log("data:", data);
        table.reload("tables", {
            where: {    //需要提交的数据
                search: data.field.keyWord,
                code: data.field.code
            },
            page: {
                curr: 1 //重新从第 1 页开始
            }
        });
        return false;
    });

    table.render({
        elem: '#tables'
        , id: 'tables'
        , height: 500
        , loading: true
        , toolbar: '<div>操作</div>'
        , title: "信息导出"
        , url: baseUrl + 'data/getLogAll' //数据接口
        , page: true //开启分页
        , defaultToolbar: ['filter', 'exports']
        , cols: [[ //表头
            {field: 'id', title: 'id', hide: true}
            , {field: 'errorCode', title: '错误编码'}
            , {field: 'errorTitle', title: '错误标题'}
            , {field: 'serverName', title: '服务名称'}
            , {field: 'host', title: '主机名'}
            , {field: 'requestUrl', title: '请求Url'}
            , {field: 'createTime', title: '错误时间'}
            , {
                field: 'action', title: '操作', templet: function (d) {
                    return '<button   onclick="openDetail(\'' + d.id + '\')" class="layui-btn layui-btn-xs ">查看错误信息</button>';
                }
            }
        ]],
        request: {
            pageName: 'current' //页码的参数名称，默认：page
            , limitName: 'size' //每页数据量的参数名，默认：limit
        },
        parseData: function (res) {
            return {
                "code": res.errorCode == "0" ? 0 : 1, //解析接口状态
                "count": res.result.total, //解析数据长度
                "data": res.result.records //解析数据列表
            }
        }
    });

});

function openDetail(id) {
    console.log("id:" + id);
    ajaxParams("data/getDetail", {
        id: id
    }, function (data) {
        vm.infos = data;
        console.log(vm.infos);
        $("#openRank").modal("show");
    });
}

var vm = new Vue({
    el: "#app",
    data: {
        infos: {}
    }
});
